package com.zone.editor;

import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.zone.editor.inter.EditorView;
import com.zone.editor.inter.EditorViewState;
import com.zone.editor.photoEditor.R;

public class Sticker extends Graphic {

    private final MultiTouchListener mMultiTouchListener;
    private final EditorView parentView;
    private final EditorViewState mViewState;
    private ImageView imageView;
    private ImageView imgPhotoEditorClose;

    public Sticker(EditorView parentView,
                   MultiTouchListener multiTouchListener,
                   EditorViewState viewState,
                   GraphicManager graphicManager
    ) {
        super(parentView.getContext(), graphicManager);
        this.parentView = parentView;
        mViewState = viewState;
        mMultiTouchListener = multiTouchListener;
        setupGesture();
    }

    public void buildView(Bitmap desiredImage) {
        int width = desiredImage.getWidth();
        int height = desiredImage.getHeight();
        ViewGroup.LayoutParams params = imgPhotoEditorClose.getLayoutParams();
        params.width = height / 5;
        params.height = height / 5;
        imgPhotoEditorClose.setLayoutParams(params);

        imageView.setImageBitmap(desiredImage);
    }

    private void setupGesture() {
        MultiTouchListener.OnGestureControl onGestureControl = buildGestureController(parentView, mViewState);
        mMultiTouchListener.setOnGestureControl(onGestureControl);
        View rootView = getRootView();
        rootView.setOnTouchListener(mMultiTouchListener);
    }


    @Override
    ViewType getViewType() {
        return ViewType.IMAGE;
    }

    @Override
    int getLayoutId() {
        return R.layout.view_photo_editor_image;
    }

    @Override
    void setupView(View rootView) {
        imageView = rootView.findViewById(R.id.imgPhotoEditorImage);
        imgPhotoEditorClose = rootView.findViewById(R.id.imgPhotoEditorClose);
    }
}
